
<title>发放工资 - 工资结算管理</title>
<div class="row">
	<div class="col-xs-12">

		<div class="widget-box">
			<div class="widget-header">选择查询条件</div>

			<div class="widget-body" style="display: block;">
				<form id="conditionForm" action="" method="post">
					<div class="widget-main">
						<div class="row">
							<div class="col-md-4  col-md-push-1 col-lg-4 col-lg-push-1">
								<label>部门</label><select id="depList"  class="form-control"></select> <br />
							</div>
							<div class="col-md-4  col-md-push-1  col-lg-4 col-lg-push-1">
								<label>发放月</label><select id="monthList"  class="form-control"></select> <br />
							</div>
							<div class="col-md-3  col-md-push-1 col-lg-3 col-lg-push-1">
								<br /> <input id="query" type="submit" value="查询"
									class="btn btn-primary" /> <input type="reset" value="重选"
									class="btn btn-primary" />
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		
		<br />
		<!-- 从工资暂存表中加载 [isDistributed]=false 工资数据 -->
		<table id="show" class="table table-bordered table-hover text-center"></table>

		<!-- 点发放即设 [isDistributed]=true -->
		<!-- <button>发放</button> -->
	</div>
</div>

<script type="text/javascript">
	var scripts = [ null, null ];

	$('.page-content-area')
			.ace_ajax(
					'loadScripts',
					scripts,
					function() {

						/* 动态加载[部门]列表 */
						$.ajax({
							type : "GET",
							url : "json/department_info.json",
							success : function(data) {
								var options = data;
								$("#depList").empty();
								$("#depList").append(
										"<option value=\"null\">请选择</option>");
								for (var i = 0; i < options.length; i++) {
									var option = options[i];
									$("#depList").append(
											"<option value=\"" + 
									option.dep_id + "\">"
													+ option.dep_name
													+ "</option>");
								}
							}
						});

						/* 动态加载[发放月]列表 */
						$("#monthList").append(
								"<option value=\"null\">请选择</option>");
						for (var i = 1; i < 13; i++) {
							$("#monthList").append(
									"<option value=\"" + i + "\">" + i
											+ "月</option>");
						}

						/* 查询参数为空的表单验证 和 异步加载查询结果 */
						$("#conditionForm")
								.bind(
										"submit",
										function() {
											var err = "";
											if ($("#depList").val() == "null") {
												err += "-- 亲，请指定 [部门] 信息 -- \n";
											}
											if ($("#monthList").val() == "null") {
												err += "- 亲，请指定 [发放月] 信息 - \n";
											}
											if (err == "") {
												/* 异步加载查询结果 */
												$
														.ajax({
															type : "GET",
															url : "json/salary_temp.json",
															success : function(
																	data) {
																var trs = data;
																$("#show")
																		.empty();
																for (var i = 0; i < trs.length; i++) {
																	var temp = trs[i];
																	/* 生成表头 */
																	if (i == 0) {
																		$(
																				"#show")
																				.append("<thead>"+
																						"<tr><th>"
																								+ temp.emp_id
																								+ "</th><th>"
																								+ temp.emp_name
																								+ "</th><th>"
																								+ temp.total_base_salary
																								+ "</th><th>"
																								+ temp.total_pension
																								+ "</th><th>"
																								+ temp.total_medical
																								+ "</th><th>"
																								+ temp.total_housing_fund
																								+ "</th><th>"
																								+ temp.total_sickleave_hold
																								+ "</th><th>"
																								+ temp.total_overwork_salary
																								+ "</th>"
																								+ "<th>操作</th></tr>"+"</thead>");
																	}
																	/* 生成数据 */
																	else {
																		$(
																				"#show")
																				.append("<tbody>"+
																						"<tr><td>"
																								+ temp.emp_id
																								+ "</td><td>"
																								+ temp.emp_name
																								+ "</td><td>"
																								+ temp.total_base_salary
																								+ "</td><td>"
																								+ temp.total_pension
																								+ "</td><td>"
																								+ temp.total_medical
																								+ "</td><td>"
																								+ temp.total_housing_fund
																								+ "</td><td>"
																								+ temp.total_sickleave_hold
																								+ "</td><td>"
																								+ temp.total_overwork_salary
																								+ "</td>"
																								+ "<td><button type='button' class='btn btn-success btn-xs' onclick=''>发放</button></td></tr>"+"</tbody>");
																	}
																}
															}
														});
												return false;
											} else {
												alert(err);
												return false;
											}
										});

					});
</script>